package models

import (
	"myRbac/utils"
	"time"
)

// 权限表结构体
type Menu struct {
	// 权限Id
	Id int `json:"id" form:"id" gorm:"column:id;type:int;auto_increment;primary_key;"`
	// 权限父Id
	Fid int `json:"fid" form:"fid" gorm:"column:fid;type:int;"`
	// 权限类型
	Type Type `json:"type" form:"type" gorm:"column:type;type:int;"`
	// 权限名
	Name string `json:"name" form:"name" gorm:"column:name;type:varchar(40);"`
	// 路由路径
	Path string `json:"path" form:"path" gorm:"column:path;type:varchar(60);"`
	// 组件路径
	Component string `json:"component" form:"component" gorm:"column:component;type:varchar(60);"`
	// 重定向路径
	Redirect string `json:"redirect" form:"redirect" gorm:"column:redirect;type:varchar(60);"`
	// 权限名，仅限于按钮
	Permission string `json:"permission" form:"permission" gorm:"column:permission;type:varchar(40);"`
	// 菜单标题
	Title string `json:"title" form:"title" gorm:"column:title;type:varchar(40);"`
	// 菜单图标
	Icon string `json:"icon" form:"icon" gorm:"column:icon;type:varchar(40);"`
	// 是否内嵌
	IsIframe int `json:"isIframe" form:"isIframe" gorm:"column:isIframe;type:int;"`
	// 是否外链
	IsLink int `json:"isLink" form:"isLink" gorm:"column:isLink;type:int;"`
	// 外链地址
	OutLink string `json:"outLink" form:"outLink" gorm:"column:outLink;type:varchar(60);"`
	// 是否隐藏
	IsHide int `json:"isHide" form:"isHide" gorm:"column:isHide;type:int;"`
	// 是否缓存
	IsKeepAlive int `json:"isKeepAlive" form:"isKeepAlive" gorm:"column:isKeepAlive;type:int;"`
	// 是否固定
	IsAffix int `json:"isAffix" form:"isAffix" gorm:"column:IsAffix;type:int;"`
	// 排序
	OrderNo int `json:"orderNo" form:"orderNo" gorm:"column:orderNo;type:int;"`
	// 状态
	Status int `json:"status" form:"status" gorm:"column:status;type:int;"`
	// 备注
	Remark string `json:"remark" form:"remark" gorm:"column:remark;type:varchar(40);"`
	// 创建时间
	CreateTime string `json:"create_time" form:"create_time" gorm:"column:create_time;type:varchar(30);"`
	// 更新时间
	UpdateTime string `json:"update_time" form:"update_time" gorm:"column:update_time;type:varchar(30);"`
	// 创建者Id
	CreateUserId int `json:"createUserId" form:"createUserId" gorm:"column:createUserId;type:int;"`
	// 更新者Id
	UpdateUserId int `json:"updateUserId" form:"updateUserId" gorm:"column:updateUserId;type:int;"`
	// 删除标记
	IsDelete int     `json:"is_delete" form:"is_delete" gorm:"column:is_delete;type:int;"`
	Role     []*Role `json:"roles" form:"-" gorm:"many2many:role_menu;"`
	Children []Menu  `json:"children" gorm:"foreignkey:Fid;association_foreignkey:Id"`
}

// vueRouter自定义字段放在meta中
type Meta struct {
	Path        string `json:"path" form:"path"`
	Component   string `json:"component" form:"component"`
	Redirect    string `json:"redirect" form:"redirect"`
	Permission  string `json:"permission" form:"permission"`
	Title       string `json:"title" form:"title"`
	Icon        string `json:"icon" form:"icon"`
	IsIframe    int    `json:"isIframe" form:"isIframe"`
	OutLink     string `json:"outLink" form:"outLink"`
	IsLink      int    `json:"isLink" form:"isLink"`
	IsHide      int    `json:"isHide" form:"isHide"`
	IsKeepAlive int    `json:"isKeepAlive" form:"isKeepAlive"`
	IsAffix     int    `json:"isAffix" form:"isAffix"`
	OrderNo     int    `json:"orderNo" form:"orderNo"`
}

// 权限类型
type Type int

// 权限类型枚举
const (
	// 目录
	DIR Type = 1
	// 菜单
	MENU Type = 2
	// 按钮
	BUTTON Type = 3
)

/*
	|--主页
	|	|--主控台
	|--系统管理
	|	|--权限管理
	|	|--角色管理
	|	|--用户管理
	|   |--部门管理
	|--工具页面
	|   |--文件列表
*/
// 插入一批菜单数据
func InsertMockMenus() {
	DB.Model(&Menu{}).Create([]Menu{
		{Id: 1, Fid: 0, Type: 2, Name: "home", Path: "/home", Component: "/home/index", Redirect: "", Permission: "", Title: "message.router.home", Icon: "ele-HomeFilled", IsIframe: 0, OutLink: "", IsLink: 0, IsHide: 0, IsKeepAlive: 1, IsAffix: 1, OrderNo: 0, Status: 1, Remark: "首页", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 2, Fid: 0, Type: 1, Name: "system", Path: "/system", Component: "layout/routerView/parent", Redirect: "/system/user", Permission: "", Title: "message.router.system", Icon: "iconfont icon-ico", IsLink: 0, IsIframe: 0, OutLink: "", IsHide: 0, IsKeepAlive: 0, IsAffix: 0, OrderNo: 0, Status: 1, Remark: "系统管理", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 3, Fid: 2, Type: 2, Name: "user", Path: "/system/user", Component: "/system/user/index", Redirect: "", Permission: "", Title: "message.router.systemUser", Icon: "iconfont icon-gerenzhongxin", IsLink: 0, IsIframe: 0, OutLink: "", IsHide: 0, IsKeepAlive: 0, IsAffix: 0, OrderNo: 0, Status: 1, Remark: "用户管理", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 4, Fid: 2, Type: 2, Name: "role", Path: "/system/role", Component: "/system/role/index", Redirect: "", Permission: "", Title: "message.router.systemRole", Icon: "iconfont icon-caidan", IsLink: 0, IsIframe: 0, OutLink: "", IsHide: 0, IsKeepAlive: 0, IsAffix: 0, OrderNo: 0, Status: 1, Remark: "角色管理", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 5, Fid: 2, Type: 2, Name: "menu", Path: "/system/menu", Component: "/system/menu/index", Redirect: "", Permission: "", Title: "message.router.systemMenu", Icon: "ele-SetUp", IsLink: 0, IsIframe: 0, OutLink: "", IsHide: 0, IsKeepAlive: 0, IsAffix: 0, OrderNo: 0, Status: 1, Remark: "权限管理", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 6, Fid: 2, Type: 2, Name: "dept", Path: "/system/dept", Component: "/system/dept/index", Redirect: "", Permission: "", Title: "message.router.systemDept", Icon: "iconfont icon-siweidaotu", IsLink: 0, IsIframe: 0, OutLink: "", IsHide: 0, IsKeepAlive: 0, IsAffix: 0, OrderNo: 0, Status: 1, Remark: "权限管理", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 7, Fid: 0, Type: 1, Name: "tool", Path: "/tool", Component: "layout/routerView/parent", Redirect: "/tool/file", Permission: "", Title: "message.router.tools", Icon: "ele-Setting", IsLink: 0, IsIframe: 0, OutLink: "", IsHide: 0, IsKeepAlive: 0, IsAffix: 0, OrderNo: 0, Status: 1, Remark: "工具页面", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 8, Fid: 7, Type: 2, Name: "file", Path: "/tool/file", Component: "/tool/file/index", Redirect: "", Permission: "", Title: "message.router.toolsFile", Icon: "iconfont icon-jinridaiban", IsLink: 0, IsIframe: 0, OutLink: "", IsHide: 0, IsKeepAlive: 0, IsAffix: 0, OrderNo: 0, Status: 1, Remark: "文件列表", CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},

		{Id: 9, Fid: 3, Type: 3, Permission: "sysUser:query", Title: "用户查询", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 10, Fid: 3, Type: 3, Permission: "sysUser:add", Title: "用户新增", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 11, Fid: 3, Type: 3, Permission: "sysUser:update", Title: "用户修改", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 12, Fid: 3, Type: 3, Permission: "sysUser:delete", Title: "用户删除", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},

		{Id: 13, Fid: 4, Type: 3, Permission: "sysRole:query", Title: "角色查询", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 14, Fid: 4, Type: 3, Permission: "sysRole:add", Title: "角色新增", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 15, Fid: 4, Type: 3, Permission: "sysRole:update", Title: "角色修改", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 16, Fid: 4, Type: 3, Permission: "sysRole:delete", Title: "角色删除", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},

		{Id: 17, Fid: 5, Type: 3, Permission: "sysMenu:query", Title: "权限查询", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 18, Fid: 5, Type: 3, Permission: "sysMenu:add", Title: "权限新增", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 19, Fid: 5, Type: 3, Permission: "sysMenu:update", Title: "权限修改", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 20, Fid: 5, Type: 3, Permission: "sysMenu:delete", Title: "权限删除", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},

		{Id: 21, Fid: 6, Type: 3, Permission: "sysDept:query", Title: "部门查询", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 22, Fid: 6, Type: 3, Permission: "sysDept:add", Title: "部门新增", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 23, Fid: 6, Type: 3, Permission: "sysDept:update", Title: "部门修改", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
		{Id: 24, Fid: 6, Type: 3, Permission: "sysDept:delete", Title: "部门删除", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), UpdateTime: utils.TimeFormatter(time.Now()), CreateUserId: 1, UpdateUserId: 1, IsDelete: 0},
	})
}
